package No0006_zigzag_conversion

import "fmt"

func convert(s string, numRows int) string {
	if numRows == 1 {
		return s
	}
	l := len(s)
	cycleLen := 2*numRows - 2
	ret := make([]byte, 0)
	for i := 0; i < numRows; i++ {
		for j := 0; j+i < l; j += cycleLen {
			ret = append(ret, s[j+i])
			if i != 0 && i != numRows-1 && j+cycleLen-i < l {
				ret = append(ret, s[j+cycleLen-i])
			}
		}
	}
	return string(ret)
}

var Test = func() {
	s := "ABCDE"
	numRows := 4
	ans := convert(s, numRows)
	fmt.Println(ans)
}
